﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <title>覆盖物-事件</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
    code{
    background: none repeat scroll 0 0 #F5F5F5;
    border: 1px dotted #778855;
    font-family: "Courier New",monospace;
    font-size: 12px;
    padding: 5px;
    width: 500px;}
    </style>
    <script type="text/javascript" src="proj/resources/javascript/jquery/jquery-1.5.2.min.js"></script>
    <script type="text/javascript" src="proj/resources/javascript/flashmap/flashmap_all.js"></script>
    <script type="text/javascript">
        $(function(){
			$("body").prepend($("<a>").attr("href","http://code.google.com/p/njcjtx/source/browse/trunk/samples/"+$("title").text()+".html").attr("target","blank").text("查看页面源码(Google Code)"));
			
            var onMapLoadHandler = function(){
                //设置当前显示区域
                map.extent([13199146.044280795, 3697106.1840964477, 13705159.17152842, 3843865.278403916]);
            
				//$("#btnAddPnt").click(function(){
					//iMap.MapPoint方法，获得一个几何点对象
					var pnt = iMap.MapPoint({
						x:13222841.52304909,
						y:3772931.7161553074
					});
					
					//iMap.Graphic方法，获得一个地图覆盖物对象
					var mark = iMap.Graphic({
						geometry:pnt
					});
					
					//为mark添加click事件
					mark.addEventListener("click",function(e){
						alert("点-click事件");
					});
					
					//向地图客户端图层添加地图覆盖物对象
					map.clientLayer.add(mark);
					
					
					//iMap.MapPoint方法，获得一个几何点对象
					var line = iMap.Polyline({
						paths:[[
							iMap.MapPoint({x:13220670.711445792,y:3774491.031532325}),
							iMap.MapPoint({x:13266869.25134135,y:3735630.446352143}),
							iMap.MapPoint({x:13296221.070202855,y:3791888.09917003}),
							iMap.MapPoint({x:13357370.692830993,y:3738076.4312572684})
						]]
					});
					//iMap.Graphic方法，获得一个地图覆盖物对象
					var linemark = iMap.Graphic({
						geometry:line
					});
					//向地图客户端图层添加地图覆盖物对象
					map.clientLayer.add(linemark);
					
					//为linemark添加mouseOver事件
					linemark.addEventListener("mouseOver",function(e){
						alert("线-mouseOver事件");
					});
					
					//iMap.MapPoint方法，获得一个几何面对象
					var pnt = iMap.Polygon({
						rings:[[
							iMap.MapPoint({x:13350032.738115618,y:3821239.9180315365}),
							iMap.MapPoint({x:13296832.566429136,y:3689156.7331547583}),
							iMap.MapPoint({x:13486396.396576365,y:3732572.9652207363}),
							iMap.MapPoint({x:13350032.738115618,y:3821239.9180315365})
						]]
					});
					//iMap.Graphic方法，获得一个地图覆盖物对象
					var polygonmark = iMap.Graphic({
						geometry:pnt
					});
					
					//为polygonmark添加mouseOut事件
					polygonmark.addEventListener("mouseOut",function(e){
						alert("面-mouseOut事件");
					});
					
					//向地图客户端图层添加地图覆盖物对象
					map.clientLayer.add(polygonmark);
				//});
			};
            
            map = new iMap({
                dom:"flashContent",
                type:"street",
                width:"100%",
                height:300,
                onLoad:onMapLoadHandler
            });
			
			
        });
    </script>
    </head>
    <body>
        <div id="flashContent" style="border:solid 1px"></div>
		<p>在地图上已经为点添加了click事件监听、为线添加了mouseOver事件监听，为面添加了mouseOut事件监听；覆盖物(点、线、面)有click, mouseOut, mouseOver, mouseDown，show，hide事件。</p>
        <div id="demo" style="postion:absolute;">
            <fieldset>
                <legend><input id="btnAddPnt" type="button" value="执行代码"></input></legend>
                <textarea id="code" style="width:1000px;">
					
				</textarea>
				<script>
					$(function(){
						$("#code").val("alert(1);");
						$("#btnAddPnt").click(function(){
							try{
								eval($("#code").val());
							}catch(e){alert("代码错误!");}
						});
					});
					</script>
            </fieldset>
        </div>
    </body>
</html>
